<table class="altrowstable" id="userListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>用户账户</th>
        <th>用户姓名</th>
        <th>添加日期</th>
        <th>锁定状态</th>
        <th>用户权限</th>
        <th>操作</th>

    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>

<div  style="position: absolute; margin-top: 0px;padding-left: 700px">
    <ul id="page">分页</ul>
</div>

<script id="userListTemplate" type="text/html">{{each data}}
    <tr>
        <td >{{$index+1}}</td>
        <td>{{$value.account}}</td>
        <td>{{$value.name}}</td>
        <td>{{$value.createDate}}</td>
        <td>{{$value.status}}</td>
        <td>
            {{each $value.power}}
                <span>{{$value.modelName}}</span>
            {{/each}}
        </td>
        <td><span style="color: #b50f11" onclick="dele(this)"  id={{$value.account}} >删除&nbsp;&nbsp;</span><span style="color: #4a5fb5;" id={{$value.name}} onclick="show2('update.html',this)">修改</span></td>
    </tr>
    {{/each}}
</script>

<script>

    function show2(url,Obj){
        var name = Obj.id
        Ajax.getHtml(url,
        function (html) {

            Ajax.post(
                "/updateUser",
                {
                    name:name
                },
                function (result) {
                    $('#account').val(result.data.account);
                    $('#password').val(result.data.password);
                    $('#name').val(result.data.name);
                    $('#createDate').val(result.data.createDate);
                    document.getElementById(result.data.status).checked=true;
                    for (var i=0;i<result.data.power.length;i++){
                        document.getElementById(result.data.power[i].modelName).checked=true;
                    }
                }
            );

            layer.open({
                type: 1,
                title: '修改用户',
                area: ['800px',['400px']],
                content: html,
                btn: ['确认', '取消'],
                yes: function () {
                    var account1=name;
                    var status='';
                    var radio=document.getElementsByName("stateCode");
                    for (var i =0;i<radio.length;i++){
                        if (radio[i].checked){
                            status=radio[i].value;

                        }
                    }
                    var radio2 = document.getElementsByName("power");
                    var powers='';
                    for (var i = 0;i<radio2.length;i++){
                        if (radio2[i].checked ===true){
                            var a=radio2[i].value;
                            powers = powers+a+","
                        }
                    }
                        Ajax.post("/updateUser2",{
                            account2:account1,
                            account:$('#account').val(),
                            name:$('#name').val(),
                            password:$('#password').val(),
                            status:status,
                            powers:powers
                        },function (result) {
                            doResult(result, function () {
                                layer.closeAll()
                                show('userList.html')
                                layer.alert(result.msg)
                            })
                        })
                },
                btn2: function () {
                    console.log('bbbb')
                }
            })

        })
    }

    $(function () {

        showPage({
            currentPage: 1,
            pageSize: 3,
            url: '/users',
            templateId: 'userListTemplate',
            contentId: 'tableBody',
        })
    })
</script>
